package com.lfz.demo.utils;

import com.lfz.demo.common.enums.CensusTimeEnum;

import javax.persistence.AttributeConverter;
import javax.persistence.Converter;

@Converter(autoApply = true)
public class CensusTimeEnumConverter implements AttributeConverter<CensusTimeEnum, Integer> {

    @Override
    public Integer convertToDatabaseColumn(CensusTimeEnum attribute) {
        return attribute != null ? attribute.getCode() : null;
    }

    @Override
    public CensusTimeEnum convertToEntityAttribute(Integer dbData) {
        return dbData != null ? CensusTimeEnum.getByCode(dbData) : null;
    }
}